package Proxy

import scala.util.Random

class HasCoin extends State {
  //transient 注解将字段标记为瞬态的,即表示一个域不是该对应串行化的一部分
  @transient
  private var mCandyMachine: CandyMachine = _

  def this(mcm: CandyMachine) {
    this
    this.mCandyMachine = mcm
  }

  override def insertCoin(): Unit = {
    println("you can't insert another coin!")
  }

  override def returnCoin(): Unit = {
    println("coin return !")
    mCandyMachine.setState(mCandyMachine.mSoldingState)
  }

  override def turnCrank(): Unit = {
    println("crank turn ...!")
    val ranwinner = new Random()
    val winner = ranwinner.nextInt(10)
    if (winner == 0) {

    } else {

    }
  }

  override def printState(): Unit = {
    println("****SoldOutState******")
  }

  //没有逻辑
  override def dispense(): Unit = ???

  override def getStateName(): String = {
    mCandyMachine.getState.getStateName()
  }
}
